package com.meng.redis.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.Component;

import java.util.Set;


/**
 * RedisHandler
 *
 * @author MENG
 * @version 2018/4/3
 * @see
 */
@Component
public class RedisHandler
{
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 获取所有key
     *
     * @return
     */
    public Set<String> getAllKeys()
    {
        return redisTemplate.keys("*");
    }

    /**
     * 是否包含 某个key
     *
     * @param key
     * @return
     */
    public boolean containsKey(Object key)
    {
        return redisTemplate.hasKey(key);
    }

    /**
     * 操作 STRING
     *
     * @return
     */
    public ValueOperations<String,String> getStrOperations()
    {
        return stringRedisTemplate.opsForValue();
    }

    /**
     * 操作 LIST
     *
     * @return
     */
    public ListOperations getListOperations()
    {
        return redisTemplate.opsForList();
    }

    /**
     * 操作 HASHMAP
     *
     * @return
     */
    public HashOperations getHashOperations()
    {
        return redisTemplate.opsForHash();
    }


    public StringRedisTemplate getStringRedisTemplate()
    {
        return stringRedisTemplate;
    }

    public RedisTemplate getRedisTemplate()
    {
        return redisTemplate;
    }
}
